package com.mybatiscore.jiaocheng.d04mybatis动态Sql;

import com.mybatiscore.Mapper.StudentMapper;
import com.mybatiscore.POJO.Student;
import com.mybatiscore.Util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

public class d03_trim {
    /*
        trim: <trim prefix="" suffix="" prefixOverrides="" suffixOverrides=""></trim>
            prefix: 加前缀
            suffix：加后缀
            prefixOverrides：删除前缀
            suffixOverrides：删除后缀
     */
    @Test
    public void testTrim(){
        SqlSession sqlSession = SqlSessionUtil.openSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        //全不为null
        List<Student> students = mapper.selectByTrim("李", '男');
        students.forEach(data -> System.out.println(data));
        //有为null
        List<Student> students1 = mapper.selectByTrim("李", null);
        students1.forEach(student -> System.out.println(student));
        List<Student> students3 = mapper.selectByTrim(null, '男');
        students3.forEach(student -> System.out.println(student));
        //全为null
        List<Student> students2 = mapper.selectByTrim(null, null);
        students2.forEach(student -> System.out.println(student));
    }
}
